/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * HlavniOkno.java
 *
 * Created on 20.11.2011, 22:01:15
 */
package gui;

import database.DatabazovaChyba;
import gui.comboBoxRenderers.ProjektComboBoxRenderer;
import gui.tableCellRenderers.ProjektCellRenderer;
import gui.tableCellRenderers.StatusCellRenderer;
import gui.tableCellRenderers.VlastnikCellRenderer;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import system.Launcher;
import ukoly.ProjektControl;
import ukoly.UkolControl;
import ukoly.UkolModel;
import ukoly.UkolStatus;
import uzivatele.Uzivatel;
import uzivatele.UzivatelRank;

/**
 *
 * @author Johny007
 */
public class HlavniOkno extends javax.swing.JFrame {

    /** Creates new form HlavniOkno */
    public HlavniOkno() {
        initComponents();
        aplikujRank(Launcher.getInstance().getUzivatel().getRank());
        Launcher.getInstance().setOknoDoprostred(this);
    }

    /**metoda aplikuje rank na dialog a umozni nebo neumozni
     * vytvoreni nebo mazani uzivatele podle prav
     * vykresli jmeno uzivatele a jeho prava do titulku
     * @param ID rank uzivatele
     */
    private void aplikujRank(int rank) {
        String pravaUzivatele = UzivatelRank.getNameFromRankId(rank);
        if (pravaUzivatele.equals("Uživatel")) {
            ButtonCreateProject.setEnabled(false);
            ButtonCreateUkol.setEnabled(false);
            ButtonDeleteProjekt.setEnabled(false);
            ButtonDeleteUkol.setEnabled(false);
        }
        String nazevOkna = "Hlavní okno"; 
        this.setTitle("Správce úkolů - " + nazevOkna +
                " - Přihlášen "+ Launcher.getInstance().getUzivatel().getEmail()
                + " - " + UzivatelRank.getNameFromRankId(rank));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        ScrollPaneProjekt = new javax.swing.JScrollPane();
        ProjektList = new javax.swing.JList();
        ScrollPaneUkolTable = new javax.swing.JScrollPane();
        UkolTable = new javax.swing.JTable();
        LabelProjekty = new javax.swing.JLabel();
        LabelUkoly = new javax.swing.JLabel();
        ButtonCreateUkol = new javax.swing.JButton();
        ButtonCreateProject = new javax.swing.JButton();
        ButtonViewProjekt = new javax.swing.JButton();
        ButtonViewUkol = new javax.swing.JButton();
        ButtonDeleteProjekt = new javax.swing.JButton();
        ButtonDeleteUkol = new javax.swing.JButton();
        ButtonZobrazUkoly = new javax.swing.JButton();
        Menu = new javax.swing.JMenuBar();
        MenuUser = new javax.swing.JMenu();
        polozkaEditace = new javax.swing.JMenuItem();
        polozkaRefresh = new javax.swing.JMenuItem();
        polozkaOdhlaseni = new javax.swing.JMenuItem();
        polozkaKonec = new javax.swing.JMenuItem();
        MenuSystem = new javax.swing.JMenu();
        polozkaSeznamUzivatelu = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        ArrayList<ProjektControl> projekty = null;

        try {
            projekty = Launcher.getInstance().getDatabase().vyberProjekty("");
        } catch(DatabazovaChyba ex) {
            JOptionPane.showMessageDialog(this.getFocusOwner(), "Chyba v komunikaci s databází\n"+ex.getMessage());
        }

        DefaultListModel listModel = new DefaultListModel();
        //listModel.addElement(null);
        for(ProjektControl p : projekty) {
            listModel.addElement(p);
        }
        ProjektList.setModel(listModel/*new javax.swing.AbstractListModel() {
            String[] strings = { "Projekt 1" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        }*/);
        ProjektList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        ProjektList.setCellRenderer(new ProjektComboBoxRenderer());
        ScrollPaneProjekt.setViewportView(ProjektList);

        UkolTable.setAutoCreateRowSorter(true);
        //ArrayList<UkolControl> ukoly = new ArrayList<UkolControl>();

        UkolTableModel model = new UkolTableModel(null);
        UkolTable.setModel(model);
        UkolTable.setDefaultRenderer(ProjektControl.class, new ProjektCellRenderer(true));
        UkolTable.setDefaultRenderer(Uzivatel.class, new VlastnikCellRenderer(true));
        UkolTable.setDefaultRenderer(UkolStatus.class, new StatusCellRenderer(true));
        UkolTable.setDragEnabled(true);
        UkolTable.setFillsViewportHeight(true);
        UkolTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        UkolTable.getTableHeader().setReorderingAllowed(false);
        UkolTable.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                UkolTableMouseClicked(evt);
            }
        });
        ScrollPaneUkolTable.setViewportView(UkolTable);
        UkolTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        UkolTable.getColumnModel().getColumn(4).setResizable(false);

        LabelProjekty.setText("Projekty");

        LabelUkoly.setText("Úkoly");

        ButtonCreateUkol.setText("Vytvoření úkolu");
        ButtonCreateUkol.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonCreateUkolActionPerformed(evt);
            }
        });

        ButtonCreateProject.setText("Vytvoření projektu");
        ButtonCreateProject.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonCreateProjectActionPerformed(evt);
            }
        });

        ButtonViewProjekt.setText("Prohlédnout projekt");
        ButtonViewProjekt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonViewProjektActionPerformed(evt);
            }
        });

        ButtonViewUkol.setText("Prohlédnout úkol");
        ButtonViewUkol.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonViewUkolActionPerformed(evt);
            }
        });

        ButtonDeleteProjekt.setText("Smazání projektu");
        ButtonDeleteProjekt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonDeleteProjektActionPerformed(evt);
            }
        });

        ButtonDeleteUkol.setText("Smazání úkolu");
        ButtonDeleteUkol.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonDeleteUkolActionPerformed(evt);
            }
        });

        ButtonZobrazUkoly.setText("Zobrazit úkoly projektu");
        ButtonZobrazUkoly.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonZobrazUkolyActionPerformed(evt);
            }
        });

        MenuUser.setText("Uživatel");

        polozkaEditace.setText("Editace");
        polozkaEditace.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                polozkaEditaceActionPerformed(evt);
            }
        });
        MenuUser.add(polozkaEditace);

        polozkaRefresh.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F5, 0));
        polozkaRefresh.setText("Refresh");
        polozkaRefresh.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                polozkaRefreshActionPerformed(evt);
            }
        });
        MenuUser.add(polozkaRefresh);

        polozkaOdhlaseni.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F10, java.awt.event.InputEvent.ALT_MASK));
        polozkaOdhlaseni.setText("Odhlásit");
        polozkaOdhlaseni.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                polozkaOdhlaseniActionPerformed(evt);
            }
        });
        MenuUser.add(polozkaOdhlaseni);

        polozkaKonec.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_F4, java.awt.event.InputEvent.ALT_MASK));
        polozkaKonec.setText("Konec");
        polozkaKonec.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                polozkaKonecActionPerformed(evt);
            }
        });
        MenuUser.add(polozkaKonec);

        Menu.add(MenuUser);

        MenuSystem.setText("Systém");

        polozkaSeznamUzivatelu.setText("Seznam uživatelů");
        polozkaSeznamUzivatelu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                polozkaSeznamUzivateluActionPerformed(evt);
            }
        });
        MenuSystem.add(polozkaSeznamUzivatelu);

        Menu.add(MenuSystem);

        setJMenuBar(Menu);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(LabelProjekty)
                            .addComponent(ScrollPaneProjekt, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(ScrollPaneUkolTable, javax.swing.GroupLayout.DEFAULT_SIZE, 652, Short.MAX_VALUE)
                            .addComponent(LabelUkoly))
                        .addContainerGap(80, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(ButtonZobrazUkoly, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(ButtonViewProjekt)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButtonViewUkol)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButtonCreateProject)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButtonCreateUkol)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButtonDeleteProjekt)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(ButtonDeleteUkol)))
                        .addContainerGap(151, Short.MAX_VALUE))))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(LabelProjekty)
                    .addComponent(LabelUkoly))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(ScrollPaneUkolTable)
                    .addComponent(ScrollPaneProjekt, javax.swing.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(ButtonZobrazUkoly)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ButtonViewProjekt)
                    .addComponent(ButtonViewUkol)
                    .addComponent(ButtonCreateProject)
                    .addComponent(ButtonCreateUkol)
                    .addComponent(ButtonDeleteProjekt)
                    .addComponent(ButtonDeleteUkol))
                .addGap(30, 30, 30))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ButtonViewProjektActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonViewProjektActionPerformed
        final ProjektControl selected = (ProjektControl) this.ProjektList.getSelectedValue();

        if (selected == null) {
            JOptionPane.showMessageDialog(this, "Není vybrán žádný projekt.");
        } else {
            java.awt.EventQueue.invokeLater(new Runnable() {

                @Override
                public void run() {
                    new VytvoreniProjektu(selected).setVisible(true);
                }
            });
        }

    }//GEN-LAST:event_ButtonViewProjektActionPerformed

    private void ButtonViewUkolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonViewUkolActionPerformed

        int selected = this.UkolTable.getSelectedRow(); // najdu vybrany radek
        
        if (selected == -1) {
            JOptionPane.showMessageDialog(this, "Není vybrán žádný úkol.");
            return;
        }
        
        UkolTableModel modelTabulky = (UkolTableModel) this.UkolTable.getModel();
        final UkolControl vybranyUkol =
                (UkolControl) modelTabulky.getRowModelAt(selected); //necham si vratit vybrany objekt
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                DetailyUkolu oknoVybranehoUkolu = new DetailyUkolu(vybranyUkol);
                oknoVybranehoUkolu.setVisible(true);
            }
        });

        /*UkolControl selected = (UkolControl) this.UkolTable.get
        
        if (selected == null) {
        JOptionPane.showMessageDialog(this.getFocusOwner(), "Není vybrán žádný úkol.");
        return;
        }
        
        ArrayList<UkolControl> al = null;
        try {
        al = Launcher.getInstance().getDatabase().vyberUkoly("WHERE project_id='" + selected.getModel().getID() + "'");
        } catch (DatabazovaChyba ex) {
        JOptionPane.showMessageDialog(this.getFocusOwner(), "Chyba v komunikaci s databází\n" + ex.getMessage());
        }*/
    }//GEN-LAST:event_ButtonViewUkolActionPerformed

    private void ButtonZobrazUkolyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonZobrazUkolyActionPerformed

        ProjektControl selected = (ProjektControl) this.ProjektList.getSelectedValue();

        if (selected == null) {
            JOptionPane.showMessageDialog(this, "Není vybrán žádný projekt.");
            return;
        }

        ArrayList<UkolControl> al = null;
        try {
            al = Launcher.getInstance().getDatabase().vyberUkoly("WHERE project_id='" + selected.getModel().getID() + "'");
        } catch (DatabazovaChyba ex) {
            JOptionPane.showMessageDialog(this, "Chyba v komunikaci s databází\n" + ex.getMessage());
        }

        UkolTableModel model;

        if (al == null || al.isEmpty()) {
            model = new UkolTableModel(null);
        } else {
            model = new UkolTableModel(al.toArray(new UkolControl[0]));
        }
        //the array in the TableModel constructor is just to tell which class array it should return
        this.UkolTable.setModel(model);

    }//GEN-LAST:event_ButtonZobrazUkolyActionPerformed

    private void ButtonDeleteProjektActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonDeleteProjektActionPerformed
        
        ProjektControl selected = (ProjektControl) this.ProjektList.getSelectedValue();

        if (selected == null) {
            JOptionPane.showMessageDialog(this, "Není vybrán žádný projekt.");
            return;
        }
        
        // Tahle mrcha vraci 0 pro YES a 1 pro NO, proc? YES je prvni... A -1 kdyz se zavre
        int n = JOptionPane.showConfirmDialog(
                this,
                "Opravdu chcete smazat vybraný projekt?\n"
                + "Tuto akci nelze vrátit!",
                "Potvrzení",
                JOptionPane.YES_NO_OPTION);

        if (n == /*0 */JOptionPane.YES_OPTION) {
            //Tak to udelejme takhle

            try {
                selected.deleteProjekt();
            } catch (DatabazovaChyba ex) {
                JOptionPane.showMessageDialog(this, "Chyba v komunikaci s databází\n" + ex.getMessage());
            }
            Launcher.getInstance().refresh();
            JOptionPane.showMessageDialog(this, "Projekt smazán.");
        }
    }//GEN-LAST:event_ButtonDeleteProjektActionPerformed

    private void ButtonDeleteUkolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonDeleteUkolActionPerformed
        
        int selected = this.UkolTable.getSelectedRow(); // najdu vybrany radek
        
        if (selected == -1) {
            JOptionPane.showMessageDialog(this, "Není vybrán žádný úkol.");
            return;
        }
        
        // Tahle mrcha vraci 0 pro YES a 1 pro NO, proc? YES je prvni...A -1 kdyz se zavre
        int n = JOptionPane.showConfirmDialog(
                this,
                "Opravdu chcete smazat vybraný úkol?\n"
                + "Tuto akci nelze vrátit!",
                "Potvrzení",
                JOptionPane.YES_NO_OPTION);
        if (n == /*0 */JOptionPane.YES_OPTION) {
            
            UkolTableModel modelTabulky = (UkolTableModel) this.UkolTable.getModel();
            UkolControl vybranyUkol =
                    (UkolControl) modelTabulky.getRowModelAt(this.UkolTable.getSelectedRow()); //necham si vratit vybrany objekt
            try {
                vybranyUkol.deleteUkol();
            } catch (DatabazovaChyba ex) {
                JOptionPane.showMessageDialog(this, "Chyba v komunikaci s databází\n" + ex.getMessage());
            }
            Launcher.getInstance().refresh();
            JOptionPane.showMessageDialog(this, "Úkol smazán.");
        }
    }//GEN-LAST:event_ButtonDeleteUkolActionPerformed

    private void UkolTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_UkolTableMouseClicked
        if (evt.getClickCount() == 2) {
            int selectedRow = this.UkolTable.getSelectedRow(); // najdu vybrany radek
            
            if(selectedRow >= 0) {    
                UkolTableModel modelTabulky = (UkolTableModel) this.UkolTable.getModel();
                final UkolControl vybranyUkol =
                        (UkolControl) modelTabulky.getRowModelAt(selectedRow); //necham si vratit vybrany objekt
                java.awt.EventQueue.invokeLater(new Runnable() {

                    @Override
                    public void run() {
                        DetailyUkolu oknoVybranehoUkolu = new DetailyUkolu(vybranyUkol);
                        oknoVybranehoUkolu.setVisible(true);
                    }
                });
            } else
                JOptionPane.showMessageDialog(this, "Není vybrán žádný úkol.");
        }
    }//GEN-LAST:event_UkolTableMouseClicked

    private void ButtonCreateProjectActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonCreateProjectActionPerformed
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new VytvoreniProjektu(null).setVisible(true);
            }
        });
    }//GEN-LAST:event_ButtonCreateProjectActionPerformed

    private void ButtonCreateUkolActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonCreateUkolActionPerformed
        
        if( this.ProjektList.getModel().getSize() < 1) {
            JOptionPane.showMessageDialog(this.getFocusOwner(), "Neexistuje žádný projekt ke kterému by šel úkol přiřadit.\n");
            return;
        }
        
        java.awt.EventQueue.invokeLater(new Runnable() {
            
            @Override
            public void run() {
                DetailyUkolu oknoVybranehoUkolu = new DetailyUkolu(null);
                oknoVybranehoUkolu.setVisible(true);
            }
        });
    }//GEN-LAST:event_ButtonCreateUkolActionPerformed

    private void polozkaOdhlaseniActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_polozkaOdhlaseniActionPerformed
        this.dispose();
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                PrihlasovaciDialog prihlasovaciOkno = new PrihlasovaciDialog();
                prihlasovaciOkno.setVisible(true);
            }
        });
    }//GEN-LAST:event_polozkaOdhlaseniActionPerformed

    private void polozkaKonecActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_polozkaKonecActionPerformed
        this.dispose();
    }//GEN-LAST:event_polozkaKonecActionPerformed

    private void polozkaSeznamUzivateluActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_polozkaSeznamUzivateluActionPerformed
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                SpravaUzivatelu oknoSpravyUzivatelu = new SpravaUzivatelu();
                oknoSpravyUzivatelu.setVisible(true);
            }
        });
    }//GEN-LAST:event_polozkaSeznamUzivateluActionPerformed

    private void polozkaEditaceActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_polozkaEditaceActionPerformed
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                VytvoreniUzivatele oknoEditaceUzivatele = new VytvoreniUzivatele(Launcher.getInstance().getUzivatel());
                oknoEditaceUzivatele.setVisible(true);
            }
        });
    }//GEN-LAST:event_polozkaEditaceActionPerformed

    private void polozkaRefreshActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_polozkaRefreshActionPerformed
        Launcher.getInstance().refresh();
    }//GEN-LAST:event_polozkaRefreshActionPerformed

    /**
     * Tohle volejte pokazdy kdyz v jinem okne udelate nejake zmeny do databaze
     */
    public void refresh() {
        ArrayList<ProjektControl> projekty = null;

        try {
            projekty = Launcher.getInstance().getDatabase().vyberProjekty("");
        } catch (DatabazovaChyba ex) {
            JOptionPane.showMessageDialog(this, "Chyba v komunikaci s databází\n" + ex.getMessage());
        }

        DefaultListModel listModel = new DefaultListModel();
        for (ProjektControl p : projekty) {
            listModel.addElement(p);
        }
        ProjektList.setModel(listModel);

        //and resets the UkolTable
        this.UkolTable.setModel(new UkolTableModel(null));
        
        aplikujRank(Launcher.getInstance().getUzivatel().getRank());
        
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ButtonCreateProject;
    private javax.swing.JButton ButtonCreateUkol;
    private javax.swing.JButton ButtonDeleteProjekt;
    private javax.swing.JButton ButtonDeleteUkol;
    private javax.swing.JButton ButtonViewProjekt;
    private javax.swing.JButton ButtonViewUkol;
    private javax.swing.JButton ButtonZobrazUkoly;
    private javax.swing.JLabel LabelProjekty;
    private javax.swing.JLabel LabelUkoly;
    private javax.swing.JMenuBar Menu;
    private javax.swing.JMenu MenuSystem;
    private javax.swing.JMenu MenuUser;
    private javax.swing.JList ProjektList;
    private javax.swing.JScrollPane ScrollPaneProjekt;
    private javax.swing.JScrollPane ScrollPaneUkolTable;
    private javax.swing.JTable UkolTable;
    private javax.swing.JMenuItem polozkaEditace;
    private javax.swing.JMenuItem polozkaKonec;
    private javax.swing.JMenuItem polozkaOdhlaseni;
    private javax.swing.JMenuItem polozkaRefresh;
    private javax.swing.JMenuItem polozkaSeznamUzivatelu;
    // End of variables declaration//GEN-END:variables
}
